package com.treasure.mall.biz.entity.life;

import com.treasure.mall.biz.entity.BasePO;
import com.treasure.mall.biz.entity.embeddable.ReceivingInfo;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.util.List;

/**
 *
 * <p> 线下店铺
 * +---------------------------------------------------------
 * * @package: com.treasure.mall.biz.entity.life
 * * @author: guomw (guomwchen@foxmail.com)
 * * @date: 2020/10/13 10:38 上午
 * * @since: V1.0.0
 * +---------------------------------------------------------
 * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的
 *
 */
@Entity
@Table(name = "zb_shop")
@Setter
@Getter
public class ShopPO extends BasePO {
    /**
     * ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 店铺名称
     */
    @Column(name = "shop_name", length = 50)
    private String title;
    /**
     * 店铺logo
     */
    @Column(name = "logo", length = 200)
    private String logo;
    /**
     * 联系电话
     */
    @Column(name = "contact_way", length = 50)
    private String contactWay;

    /**
     * 掌眼服务
     */
    @Column(name = "is_palm_eye_service")
    private boolean palmEyeService;
    /**
     * 修复服务
     */
    @Column(name = "is_repair_service")
    private boolean repairService;

    /**
     * 学院服务
     */
    @Column(name = "is_school_service")
    private boolean schoolService;

    /**
     * 是否推荐
     */
    @Column(name = "is_recommend")
    private boolean recommend;
    /**
     * 冻结
     */
    @Column(name = "is_disabled")
    private boolean disabled;

    /**
     * 经营时间
     */
    @Column(name = "business_hours", length = 50)
    private String businessHours;

    @ManyToMany(fetch = FetchType.EAGER)
    @Fetch(FetchMode.SUBSELECT)
    @JoinTable(name = "zb_shop_business_scope_rel", joinColumns = {@JoinColumn(name = "shop_id")}
            , inverseJoinColumns = {@JoinColumn(name = "scope_id")})
    private List<ShopBusinessScopePO> businessScopes;


    @ManyToMany(fetch = FetchType.EAGER)
    @Fetch(FetchMode.SUBSELECT)
    @JoinTable(name = "zb_shop_business_tags_rel", joinColumns = {@JoinColumn(name = "shop_id")}
            , inverseJoinColumns = {@JoinColumn(name = "tags_id")})
    private List<ShopBusinessTagsPO> businessTags;

    /***
     * 地址地址
     */
    private ReceivingInfo shopAddress;
    /**
     * 经维度 120.177158,30.264785
     */
    @Column(name = "lnglat", length = 100)
    private String lnglat;
    /**
     * 详细信息
     */
    @Column(name = "details")
    private String details;

    /**
     * 线上店铺ID
     */
    @Column(name = "online_merchant_id")
    private Long onlineMerchantId;

    @Column(name = "remark", length = 100)
    private String remark;


    public String scopesStr() {
        StringBuilder str = new StringBuilder();
        if (businessScopes != null && businessScopes.size() > 0) {
            businessScopes.forEach(v -> {
                str.append(v.getTitle() + " ");
            });
        }
        return str.toString();
    }


    public String tagsToStr() {
        StringBuilder str = new StringBuilder();
        if (this.palmEyeService) {
            str.append("掌眼 ");
        }
        if (this.repairService) {
            str.append("修复 ");

        }
        if (businessTags != null && businessTags.size() > 0) {
            businessTags.forEach(v -> {
                str.append(v.getTitle() + " ");
            });
        }
        return str.toString();
    }
}
